package com.hzit.cart.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Configuration
//@Import(HzitImportSelector.class)       // 一次性可以加载多个类
//@Import(SmsUtil.class)                    // 一次性加载一个类
@EnableRedisHttpSession
public class HzitSessionConfig {

	// 1. 对redis进行序列化配置
	@Bean
	public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
		return new GenericJackson2JsonRedisSerializer();
	}
	@Bean
	public CookieSerializer cookieSerializer() {
		DefaultCookieSerializer serializer = new DefaultCookieSerializer();
		serializer.setCookieName("HZIT-COOKIE");
		serializer.setDomainName("hzit.com");       // 这样配置域名后，就会对hzit.com这个一级域名及其下的二级、三级域名起作用（实际session共享）
		// serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
		return serializer;
	}

}
